package test.datasource;

import jasmine.framework.common.util.ErrorUtil;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author mh.z
 */
public class UnitTestConnection extends ConnectionWrapper {

    public UnitTestConnection(Connection targetConnection) {
        super(targetConnection);
    }

    @Override
    public void commit() throws SQLException {
        //
    }

    @Override
    public void rollback() throws SQLException {
        super.rollback();
    }

    @Override
    public void close() throws SQLException {
        //
    }

    /**
     * 强制提交
     */
    public void forceCommit() {
        try {
            targetConnection.commit();
        } catch (SQLException e) {
            throw ErrorUtil.sneakyError(e);
        }
    }

    /**
     * 强制回滚
     */
    public void forceRollback() {
        try {
            targetConnection.rollback();
        } catch (SQLException e) {
            throw ErrorUtil.sneakyError(e);
        }
    }

    /**
     * 强制关闭
     */
    public void forceClose() {
        try {
            targetConnection.close();
        } catch (SQLException e) {
            throw ErrorUtil.sneakyError(e);
        }
    }

}
